#include <AST/expr/control/ReturnAST.hpp>
#include <global.hpp>

Return::Return(Expr *returnValue) : returnValue(returnValue) {
}

llvm::Value *Return::codegen() {
    if (builder.GetInsertBlock()->getTerminator() != nullptr)
        return logWarning("Return::codegen: Return is ignored due to"
                          " a terminator is found");
    return returnValue != nullptr ? builder.CreateRet(returnValue->codegen())
                                  : builder.CreateRetVoid();
}